package com.gonghui.videomanage;

import android.content.Context;
import android.os.PowerManager;
import android.util.Log;

/**
 * Created by zy on 2016/8/19.
 */
public class WakeLockUtil {
    private static WakeLockUtil wakeLockUtil = new WakeLockUtil();
    private static PowerManager.WakeLock wakeLock;

    private WakeLockUtil(){}

    public static WakeLockUtil getInstance(Context context) {
        if (wakeLock == null) {
            PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
            wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Lock");
        }
        return wakeLockUtil;
    }

    public void open(){
        wakeLock.acquire();
        Log.i("WakeLockUtil", "open: ");
    }
    public void close(){
        if (wakeLock.isHeld()) {
            wakeLock.release();
            Log.i("WakeLockUtil", "close: ");
        }
    }
}
